package com.songlanyun.modules.sharebenefitconfig.controller.admin;

import com.songlanyun.common.enums.CommonwealConstant;
import com.songlanyun.common.enums.GoodsConstant;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;
import com.songlanyun.common.validator.ValidatorUtils;
import com.songlanyun.modules.sharebenefitconfig.entity.CommonwealShareBenefitConfigEntity;
import com.songlanyun.modules.sharebenefitconfig.model.IShareBenefitConfig;
import com.songlanyun.modules.sharebenefitconfig.model.dto.CommonwealShareBenefitConfigDTO;
import com.songlanyun.modules.sharebenefitconfig.service.CommonwealShareBenefitConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;


/**
 * 公益分润配置
 *
 * @author wuchao
 * @email songlanyun@gmail.com
 * @date 2022-08-16 15:00:17
 */
@RestController
@RequestMapping("/admin/commonweal/share/benefit/config")
public class CommonwealShareBenefitConfigAdminController {
    @Autowired
    private CommonwealShareBenefitConfigService commonwealShareBenefitConfigService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions(":commonwealsharebenefitconfig:list")
    public R list() {
        List<CommonwealShareBenefitConfigEntity> list = commonwealShareBenefitConfigService.queryList();

        return R.ok().put("list", list);
    }


    /**
     * 信息
     */
    @GetMapping("/getByType/{type}")
    //@RequiresPermissions(":commonwealsharebenefitconfig:info")
    public R getByType(@PathVariable("type") Integer type) {
        IShareBenefitConfig config = commonwealShareBenefitConfigService.getByType(CommonwealConstant.ShareBenefitConfigType.getByCode(type));

        return R.ok().put("data", config);
    }

    /**
     * 保存
     */
    @PostMapping("/add")
    public R add(@RequestBody CommonwealShareBenefitConfigDTO dto) {
        ValidatorUtils.validateEntity(dto);
        commonwealShareBenefitConfigService.add(dto);

        return R.ok();
    }

    /**
     * 根据资格获取公益联盟合伙人配置
     */
    @GetMapping("/getPartnerConfigByQualification/{qualification}")
    //@RequiresPermissions(":commonwealsharebenefitconfig:info")
    public R getPartnerConfigByQualification(@PathVariable("qualification") Integer qualification) {
        return R.ok().put("data", commonwealShareBenefitConfigService.getPartnerConfigByQualification(GoodsConstant.ServicePackageArea.getByCode(qualification)));
    }

}
